package com.oner365.test.string;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.oner365.test.stream.ParallelStreamDemo;

public class StringUtils {
  
  private static final Logger LOGGER = LoggerFactory.getLogger(ParallelStreamDemo.class);

  public static void main(String[] args) {
    LOGGER.info("test:{}",String.format("%04d", 2));
    List<String> list = subString("00000002004500130014",4);
    LOGGER.info("value:{}",list.stream().collect(Collectors.joining(",")));
    List<String> list1 = subStringCode("00000002004500130014",4);
    LOGGER.info("value:{}",list1.stream().collect(Collectors.joining(",")));

  }
  
  //直接取能被整除的，特殊需求问题
  public static List<String> subString(String str,int length) {
    int strLength = str.length();
    int count = strLength / length;
    int start = 0;
    int end = length;
    List<String> list = new ArrayList<>();
    for(int i = 0;i < count;i++) {
      LOGGER.info("index:{},length:{}",start,end);
      list.add(str.substring(start, end));
      start += length;
      end += length;
     
    }
    return list;
  }
  
//直接取能被整除的，特殊需求问题
  public static List<String> subStringCode(String str,int length) {
    int strLength = str.length();
    int count = strLength / length;
    int start = 0;
    int end = length;
    List<String> list = new ArrayList<>();
    for(int i = 0;i < count;i++) {
      LOGGER.info("index:{},length:{}",start,end);
      list.add(str.substring(start, end));
      end += length;
     
    }
    return list;
  }

}
